package com.hm.hsw1;

import java.util.Random;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Integer> ts = new TreeSet<>();
        Random r = new Random();
        //产生随机数,存入集合
        for (int i = 0; i < 10; i++) {
            boolean flag = true;
            int i1 = r.nextInt(51);
            for (Integer t : ts) {
                if (t == i1) {
                    flag = false;
                    i--;
                    break;
                }
            }
            if (flag) {
                ts.add(i1);
            }
        }
        //遍历集合
        ts.forEach(i -> System.out.print(i + " "));
        System.out.println();
        //存入集合时利用比较器自定义排序规则
        TreeSet<Integer> ts1 = new TreeSet<>((o1, o2) -> o2 - o1);
        for (int i = 0; i < 10; i++) {
            boolean flag = true;
            int i1 = r.nextInt(51) + 50;
            for (Integer t : ts) {
                if (t == i1) {
                    flag = false;
                    i--;
                    break;
                }
            }
            if (flag) {
                ts1.add(i1);
            }
        }
         ts1.forEach(i -> System.out.print(i + " "));
    }
}
